<?php
namespace app\admin\model;
class query
{
  //获取活动帖子访问量
  public  static function get_activityBrowseNum()
  {
  $currentTime = strtotime(date('y-m-d'));
  $browseInfo = \think\Db::query("select t1.businessId,t1.type,t1.browseCount,ifnull(t2.shareNum,0) as shareNum from (select businessId,type,count(1) as browseCount from youhuer_browse_record t where browseTime >= {$currentTime}  and controller = 'Activity' and appName = 'getacitivitydetails'
group by businessId order by browseCount desc) t1 left join (select businessId,count(1) as shareNum from youhuer_share_record where shareTime >= {$currentTime} and businessType = 1 and businessId <> 'hall' group by businessId) t2 on  t1.businessId = t2.businessId;");
  foreach($browseInfo as &$list)
  {
   if($list['type']==1)
   {
   $activityId = $list['businessId'];
   $list['Info']= \think\Db::query("select Title,DATE_FORMAT(releaseTime, '%y-%m-%d') as releaseTime,appBrowseCount from youhuer.ocenter_activity where activityId = '{$activityId}' limit 1")[0];
   }

  }
  return $browseInfo;
  }
  //获取用户统计信息
  public static function get_userStatistics()
  {
  $userCount =  \think\Db::query("select count(1) as userCount from youhuer_wxuser where status = 1")[0]['userCount'];
  $currentTime = strtotime(date('y-m-d'));
  $thatDayUserCount = \think\Db::query("select count(1) as thatDayUserCount from youhuer_wxuser where status = 1 and registerTime >= {$currentTime}")[0]['thatDayUserCount'];
  $result  = \think\Db::query("select count(1) as browseCount,count(distinct(browseUid)) as browseUserCount from youhuer_browse_record where browseTime >= {$currentTime} and controller = 'Activity' and appName = 'getacitivitydetails'")[0];
  $browseCount = $result['browseCount'];
  $browseUserCount = $result['browseUserCount'];
  $weekTime = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)));
  $thatWeekUserCount = \think\Db::query("select count(1) as thatWeekUserCount from youhuer_wxuser where status = 1 and registerTime >= {$weekTime}")[0]['thatWeekUserCount'];
  $thatWeekUsrRatio = round($thatWeekUserCount/($userCount-$thatWeekUserCount),3)*100;
  $thatMonthTime = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00')));
  $thatMonthUserCount = \think\Db::query("select count(1) as thatMonthUserCount from youhuer_wxuser where status = 1 and registerTime >= {$thatMonthTime}")[0]['thatMonthUserCount'];
  $thatMonthUserRatio = round($thatMonthUserCount/($userCount-$thatMonthUserCount),3)*100;
  return array('userCount'=>$userCount,'thatDayUserCount'=>$thatDayUserCount,'browseCount'=>$browseCount,'browseUserCount'=>$browseUserCount,'thatWeekUserCount'=>$thatWeekUserCount,'thatMonthUserCount'=>$thatMonthUserCount,'thatWeekUsrRatio'=>$thatWeekUsrRatio,'thatMonthUserRatio'=>$thatMonthUserRatio);
  }




}